<?php

namespace app\model;

class AdminsModel extends BaseModel
{
    /**
     * 与模型关联的表名
     *
     * @var string
     */
    protected $table = 'admins';

    /**
     * 可批量赋值的属性
     *
     * @var array
     */
    protected $fillable = [
        'id',
        'username',
        'password',
        'real_name',
        'email',

        'avatar',
        'bio',
        'role_id',
        'status',
        'last_login_time',
        'last_login_ip'
    ];

    protected $hidden = ['password'];
    
    protected $casts = [
        'created_at' => 'date:Y-m-d H:i:s',
        'updated_at' => 'date:Y-m-d H:i:s',
        'last_login_time' => 'date:Y-m-d H:i:s',
    ];
    
    /**
     * 获取用户关联的角色
     */
    public function role()
    {
        return $this->belongsTo(RolesModel::class, 'role_id', 'id');
    }
}